package com.ctu.gzero.edit
{
	import com.ctu.gzero.event.DomEvent;
	import com.ctu.gzero.operation.DomTextOperation;
	
	import flash.events.TextEvent;
	
	import mx.events.StyleEvent;
	
	public class EditManager extends SelectionManager
	{
		public function EditManager()
		{
			super();
		}
		
		private function defaultOperationState(operationState:SelectionState = null) : SelectionState
        {
            if (!operationState)
            {
                return selectionState;
            }
            
            return operationState;
        }
        
		override public function textInputHandler(event:TextEvent):void
		{
			this.insertText(event.text);
		}
		
		public function insertText(text:String, selectionState:SelectionState = null):void
		{
			var operationState:SelectionState = this.defaultOperationState(selectionState);
			var op:DomTextOperation = new DomTextOperation(text, operationState);
			
			var resultState:SelectionState = op.doOperation();
			
			this.dom.normalize();
			this.dom.dispatchEvent(new DomEvent(DomEvent.DOM_OPERATIOIN_END, dom));
			this.dom.composer.reUpdateDisplay();
			
			if(resultState)
            	this.updateSelectionAndShape(resultState);
		}
	}
}
